

import java.util.Random;

import javax.swing.*;

public class BookLibraryInterface {

	public static void main(String[] args) {
		mainInterface();
	}

	static void mainInterface() {
		int option = Integer
				.parseInt(JOptionPane.showInputDialog("Type the desired option: \n 1-Isert book\n 2-Insert random books\n 3-Sort By Title\n 4-End"));
		switch (option) {
		case 1:
			insertBookInterface();
			mainInterface();
			break;
		case 2:
			insertrRandomBookInterface();
			BookDatabank.listBooks();
			mainInterface();
			break;
		case 3:
			BookDatabank.sortByTitle();
			BookDatabank.listBooks();
			mainInterface();
			break;
		case 4:
			break;
		default:
			break;
		}
	}

	public static void insertBookInterface() {
		/*
		 * JLabel password = new JLabel("Password"); JPasswordField
		 * passwordField = new JPasswordField();
		 */
		JLabel titleText = new JLabel("Title");
		JTextField titleField = new JTextField();
		JLabel authorText = new JLabel("Author");
		JTextField authorField = new JTextField();
		JLabel publisherText = new JLabel("Publisher");
		JTextField publisherField = new JTextField();
		JLabel themeText = new JLabel("Theme");
		JTextField themeField = new JTextField();
		JLabel priceText = new JLabel("Price");
		JTextField priceField = new JTextField();
		JComponent[] inputs = new JComponent[] { titleText, titleField, authorText, authorField, publisherText, publisherField, themeText, themeField,
				priceText, priceField };

		JOptionPane.showMessageDialog(null, inputs, "", JOptionPane.PLAIN_MESSAGE);

		BookDatabank.insertBook(titleField.getText(), authorField.getText(), publisherField.getText(), themeField.getText(),
				Double.parseDouble(priceField.getText()));

	}

	public static void insertrRandomBookInterface() {

		int numberOfBooks = Integer.parseInt(JOptionPane.showInputDialog("How many books?"));

		for (int i = 0; i <= numberOfBooks - 1; i++) {
			String title = Utilities.randomString(8);
			String author = Utilities.randomString(8);
			String publisher = Utilities.randomString(8);
			String theme = Utilities.randomString(8);
			double price = Utilities.randNumber(0, 100);
			BookDatabank.insertBook(title, author, publisher, theme, price);

		}

	}

}
